home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 97 / CD-ROM 97 / CD-ROM 97.iso / internet / ghostzilla / ghsetup.exe / chrome / comm.jar / content / editor / EdPageProps.js < prev    next >
Encoding:
JavaScript  |  2002-04-09  |  4.2 KB  |  159 lines

  1. /* 
  2.  * The contents of this file are subject to the Netscape Public
  3.  * License Version 1.1 (the "License"); you may not use this file
  4.  * except in compliance with the License. You may obtain a copy of
  5.  * the License at http://www.mozilla.org/NPL/
  6.  *  
  7.  * Software distributed under the License is distributed on an "AS
  8.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9.  * implied. See the License for the specific language governing
  10.  * rights and limitations under the License.
  11.  *  
  12.  * The Original Code is Mozilla Communicator client code, released
  13.  * March 31, 1998.
  14.  * 
  15.  * The Initial Developer of the Original Code is Netscape
  16.  * Communications Corporation. Portions created by Netscape are
  17.  * Copyright (C) 1998-1999 Netscape Communications Corporation. All
  18.  * Rights Reserved.
  19.  * 
  20.  * Contributor(s): 
  21.  */
  22.  
  23. var newTitle = "";
  24. var author = "";
  25. var description = "";
  26. var authorElement;
  27. var descriptionElement;
  28. var insertNewAuthor = false;
  29. var insertNewDescription = false;
  30. var titleWasEdited = false;
  31. var authorWasEdited = false;
  32. var descWasEdited = false;
  33.  
  34. //Cancel() is in EdDialogCommon.js
  35. // dialog initialization code
  36. function Startup()
  37. {
  38.   if (!InitEditorShell())
  39.     return;
  40.  
  41.   gDialog.PageLocation     = document.getElementById("PageLocation");
  42.   gDialog.TitleInput       = document.getElementById("TitleInput");
  43.   gDialog.AuthorInput      = document.getElementById("AuthorInput");
  44.   gDialog.DescriptionInput = document.getElementById("DescriptionInput");
  45.   
  46.   // Default string for new page is set from DTD string in XUL,
  47.   //   so set only if not new doc URL
  48.   var location = GetDocumentUrl();
  49.   var lastmodString = GetString("Unknown");
  50.  
  51.   if (!IsUrlAboutBlank(location))
  52.   {
  53.     // NEVER show username and password in clear text
  54.     gDialog.PageLocation.setAttribute("value", StripPassword(location));
  55.  
  56.     // Get last-modified file date+time
  57.     // TODO: Convert this to local time?
  58.     var lastmod = editorShell.editorDocument.lastModified;  // get string of last modified date
  59.  
  60.     // Convert modified string to date (0 = unknown date or January 1, 1970 GMT)
  61.     if (Date.parse(lastmod))
  62.       lastmodString = lastmod;
  63.   }
  64.   document.getElementById("PageModDate").setAttribute("value", lastmodString);
  65.  
  66.   authorElement = GetMetaElement("author");
  67.   if (!authorElement)
  68.   {
  69.     authorElement = CreateMetaElement("author");
  70.     if (!authorElement)
  71.     {
  72.       window.close();
  73.       return;
  74.     }
  75.     insertNewAuthor = true;
  76.   }
  77.  
  78.   descriptionElement = GetMetaElement("description");
  79.   if (!descriptionElement)
  80.   {
  81.     descriptionElement = CreateMetaElement("description");
  82.     if (!descriptionElement)
  83.       window.close();
  84.  
  85.     insertNewDescription = true;
  86.   }
  87.   
  88.   InitDialog();
  89.  
  90.   SetTextboxFocus(gDialog.TitleInput);
  91.  
  92.   SetWindowLocation();
  93. }
  94.  
  95. function InitDialog()
  96. {
  97.   gDialog.TitleInput.value = editorShell.GetDocumentTitle();
  98.   var author = TrimString(authorElement.getAttribute("content"));
  99.   if (author.length == 0)
  100.   {
  101.     // Fill in with value from editor prefs
  102.     var prefs = GetPrefs();
  103.     if (prefs) 
  104.       author = prefs.getCharPref("editor.author");
  105.   }
  106.   gDialog.AuthorInput.value = author;
  107.   gDialog.DescriptionInput.value = descriptionElement.getAttribute("content");
  108. }
  109.  
  110. function TextboxChanged(ID)
  111. {
  112.   switch(ID)
  113.   {
  114.     case "TitleInput":
  115.       titleWasEdited = true;
  116.       break;
  117.     case "AuthorInput":
  118.       authorWasEdited = true;
  119.       break;
  120.     case "DescriptionInput":
  121.       descWasEdited = true;
  122.       break;
  123.   }
  124. }
  125.  
  126. function ValidateData()
  127. {
  128.   newTitle = TrimString(gDialog.TitleInput.value);
  129.   author = TrimString(gDialog.AuthorInput.value);
  130.   description = TrimString(gDialog.DescriptionInput.value);
  131.   return true;
  132. }
  133.  
  134. function onAccept()
  135. {
  136.   if (ValidateData())
  137.   {
  138.     editorShell.BeginBatchChanges();
  139.     if (titleWasEdited)
  140.     {
  141.       // Set title contents even if string is empty
  142.       //  because TITLE is a required HTML element
  143.       editorShell.SetDocumentTitle(newTitle);
  144.     }
  145.     
  146.     if (authorWasEdited)
  147.       SetMetaElementContent(authorElement, author, insertNewAuthor);
  148.     if (descWasEdited)
  149.       SetMetaElementContent(descriptionElement, description, insertNewDescription);
  150.  
  151.     editorShell.EndBatchChanges();
  152.  
  153.     SaveWindowLocation();
  154.     return true; // do close the window
  155.   }
  156.   return false;
  157. }
  158.  
  159.